package com.hc.demo_api820.mapper;

import com.hc.demo_api820.domain.Orders;
import com.hc.demo_api820.dto.CalendarResponseDto;
import com.hc.demo_api820.dto.OrdersMapperDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrdersMapper {

    /**
     * 根据userId和OrdersDate查询订单，看当天有没有预约
     * */
    @Select("select orderId, orderDate, userId, hpId, smId, state from orders where userId=#{userId} and orderDate=#{orderDate}")
    List<Orders> selectByUserIdAndOrdersDate(Orders orders);

    @Select("select orderId, orderDate, userId, hpId, smId, state from orders where userId=#{userId} order by orderDate desc")
    List<Orders> selectByUserId( String userId);

    //
    int selectAlreadyAppointmentNoumber(Orders orders);


//    使用useGeneratedKeys返回自增主键
    @Insert("INSERT INTO orders(orderId,userId,hpId,smId,state,orderDate)"+
            "VALUES (#{orderId},#{userId},#{hpId},#{smId},#{state},#{orderDate})")
    @Options(useGeneratedKeys = true, keyProperty = "orderId")
    int insertOrder(Orders orders);

    int deleteByPrimaryKey(Integer orderId);

    int insert(Orders record);

    int insertSelective(Orders record);

    Orders selectByPrimaryKey(Integer orderId);

    int updateByPrimaryKeySelective(Orders record);

    int updateByPrimaryKey(Orders record);

    //如何查询某天某个医院已经约号的数量：2025年4月23号 医院编号时1 订单有3个 200-3=197
    int selectAppointmentCountByhpidByDate(Orders orders);

    List<CalendarResponseDto> listOrdersAppointmentNumber(List<OrdersMapperDto> parameList);
}